<!-- 表单弹窗 -->
<form id="dashang-form" lay-filter="dashang-form" class="layui-form model-form" style="overflow:auto; height:500px;width:90%;">
    <input name="id" type="hidden"/>
    				    <div class="layui-form-item">
        <label class="layui-form-label">金额</label>
        <div class="layui-input-block">
            <input name="price" placeholder="请输入金额" type="text" class="layui-input" maxlength="20"  id="price"
                   lay-verify="required" required/>
        </div>
    </div>
 		    <div class="layui-form-item">
        <label class="layui-form-label">图片(未选)</label>
        <div class="layui-input-block">
            <!--<input name="image" placeholder="请输入图片" type="text" class="layui-input" maxlength="20"  id="image"-->
                   <!--lay-verify="required" required/>-->
            <input type="hidden" name="image"   id="image" class="layui-input"     />
            <img id="displayimage" src="" width="50" />

            <button type="button" class="layui-btn"  id="uploadUrl"   lay-filter="uploadFile">
                <i class="layui-icon">&#xe67c;</i>选择图片
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图片(选中)</label>
        <div class="layui-input-block">
            <!--<input name="image2" placeholder="请输入图片" type="text" class="layui-input" maxlength="20"  id="image2"-->
                   <!--lay-verify="required" required/>-->
            <input type="hidden" name="image2"   id="image2" class="layui-input"     />
            <img id="displayimage2" src="" width="50" />

            <button type="button" class="layui-btn"  id="uploadUrl2"   lay-filter="uploadFile">
                <i class="layui-icon">&#xe67c;</i>选择图片
            </button>
        </div>
    </div>
     <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="user-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form', 'formSelects','upload','config'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var upload = layui.upload;
        var config = layui.config;
 
        var dashang = admin.getTempData('t_dashang');
           if (dashang.method=="update"){
               $("#displayimage2").attr("src",dashang.image2);
               $("#displayimage").attr("src",dashang.image);
        	form.val('dashang-form', dashang);
            form.render();
        }
        // 表单提交事件
        form.on('submit(user-form-submit)', function (data) {
             layer.load(2);
            
            admin.req('sys/dashang/'+dashang.method, JSON.stringify(data.field), function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg(data.msg, {icon: 1, time: 500});
                    admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 500});
                }
            }, "post");  
            return false;
        });

        //创建一个上传组件 remarkuploadUrl
        upload.render({
            elem: '#uploadUrl'
            ,url:config.base_server+'file/uploadFile'
            ,accept: "images"
            ,before: function(o){
                console.log(o)
            }
            ,done: function(res, index, upload){ //上传后的回调
                if(res.code==0){
                    $('#displayimage').attr("src", res.data.url);
                    $('#image').val(res.data.url);
                }
            }
        });
        //创建一个上传组件 remarkuploadUrl
        upload.render({
            elem: '#uploadUrl2'
            ,url:config.base_server+'file/uploadFile'
            ,accept: "images"
            ,before: function(o){
                console.log(o)
            }
            ,done: function(res, index, upload){ //上传后的回调
                if(res.code==0){
                    $('#displayimage2').attr("src", res.data.url);
                    $('#image2').val(res.data.url);
                }
            }
        });
    });
</script>
